#include "Header.h"

#ifndef ESP01S_MQTT_WEB_GLOBALCONFIG_H
#define ESP01S_MQTT_WEB_GLOBALCONFIG_H

// 全局配置类
class GlobalConfig {
public:
    // 获取单例实例
    static GlobalConfig& getInstance();

    // 禁用拷贝构造函数和赋值运算符，确保单例模式
    GlobalConfig(const GlobalConfig&) = delete;
    GlobalConfig& operator=(const GlobalConfig&) = delete;

    // WiFi 相关配置的 getter 和 setter
    std::string getWifiSsid() const;
    void setWifiSsid(const std::string& wifiSsid);
    std::string getWifiPassword() const;
    void setWifiPassword(const std::string& wifiPassword);

    // MQTT 相关配置的 getter 和 setter
    std::string getMqttServer() const;
    void setMqttServer(const std::string& mqttServer);
    std::string getMqttSslca() const;
    void setMqttSslca(const std::string& mqttSslca);
    std::string getMqttPort() const;
    void setMqttPort(const std::string& mqttPort);
    std::string getMqttClientId() const;
    void setMqttClientId(const std::string& mqttClientId);
    std::string getMqttUser() const;
    void setMqttUser(const std::string& mqttUser);
    std::string getMqttPassword() const;
    void setMqttPassword(const std::string& mqttPassword);
    std::string getMqttTopicControl() const;
    void setMqttTopicControl(const std::string& mqttTopicControl);
    std::string getMqttTopicStatus() const;
    void setMqttTopicStatus(const std::string& mqttTopicStatus);
    std::string getMqttTopicTimer() const;
    void setMqttTopicTimer(const std::string& mqttTopicTimer);
    std::string getMqttTopicResetTimer() const;
    void setMqttTopicResetTimer(const std::string& mqttTopicResetTimer);

    // HTTP 相关配置的 getter 和 setter
    std::string getHttpApiUrl() const;
    void setHttpApiUrl(const std::string& httpApiUrl);
    std::string getMqttSslcaOpen() const;
    void setMqttSslcaOpen(const std::string& mqttSslcaOpen);
    std::string getHttpApiType() const;
    void setHttpApiType(const std::string& httpApiType);

    // 错误次数和时间配置的 getter 和 setter
    void setWifiErrSec(const unsigned int& wifiErrSec);
    void setStartTime(const unsigned long& startTime);
    void setSwitchStatus(const bool& switchStatus);
    unsigned int getWifiErrSec() const;
    unsigned int getWifiErrSecOpenWebConf() const;
    void setWifiErrSecOpenWebConf(const unsigned int& wifiErrSecOpenWebConf);
    unsigned int getWebServerEndSecSet() const;
    void setWebServerEndSecSet(const unsigned int& webServerEndSecSet);
    unsigned int getWebServerEndSec() const;
    void setWebServerEndSec(const unsigned int& webServerEndSec);
    unsigned int getMqttErrSec() const;
    void setMqttErrSec(const unsigned int& mqttErrSec);
    unsigned int getMqttErrSecOpenWebConf() const;
    void setMqttErrSecOpenWebConf(const unsigned int& mqttErrSecOpenWebConf);

    // 定时开关时间的 getter 和 setter
    unsigned long getStartTime() const;
    unsigned long getEndTime() const;
    void setEndTime(const unsigned long& endTime);

    // 开关状态的 getter 和 setter
    bool isSwitchStatus() const;

    // 读取和保存配置文件的方法
    void readConfig();
    void saveConfig();

private:
    // 私有构造函数和析构函数，确保只能通过 getInstance() 获取实例
    GlobalConfig();
    ~GlobalConfig();

    // 全局参数
    // WiFi 配置
    std::string wifiSSID;
    std::string wifiPassword;

    // MQTT 配置
    std::string mqttServer;
    std::string mqttSSLCA;
    std::string mqttPort;
    std::string mqttClientId;
    std::string mqttUser;
    std::string mqttPassword;
    std::string mqttTopicControl;
    std::string mqttTopicStatus;
    std::string mqttTopicTimer;
    std::string mqttTopicResetTimer;

    // HTTP 配置
    std::string httpApiUrl;
    std::string mqttSSLCAOpen;
    std::string httpApiType;

    // 错误次数和时间配置
    unsigned int wifiErrSec = 0;
    unsigned int wifiErrSecOpenWebConf = 10;
    unsigned int webServerEndSecSet = 15;
    unsigned int webServerEndSec = 0;
    unsigned int mqttErrSec = 0;
    unsigned int mqttErrSecOpenWebConf = 1;

    // 定时开关时间
    unsigned long startTime = 0;
    unsigned long endTime = 0;
    // 开关状态
    bool switchStatus = false;

};
#endif // GLOBALCONFIG_H